
#ifndef __TIME_COUNTER_H__
#define __TIME_COUNTER_H__

class cTimeCounter
{
public:
	cTimeCounter()
	{
		Clear();
	}

	cTimeCounter(float duration)
	{
		Init(duration);
	}

	~cTimeCounter() {}

	inline void Init(float duration, float startTime = 0.0f);
	inline void Update(float dt);
	
	inline bool IsDone() const { return m_done; }
	inline bool IsUsing() const;

	inline float GetTimer() const { return m_timer; }
	inline float GetRemainTime() const { return m_duration - m_timer; }
	inline float GetDuration() const { return m_duration; }

	inline void Reset();
	inline void Clear();
	inline void Continue();

private:
	bool m_done;
	float m_duration;
	float m_timer;
};

inline void cTimeCounter::Init(float duration, float startTime)
{
	m_duration = duration;
	m_timer = startTime;
	m_done = false;
}

inline void cTimeCounter::Update(float dt)
{
	if (m_done == true)
	{
		return;
	}

	m_timer += dt;
	if (m_timer >= m_duration)
	{
		m_done = true;
	}
}

inline bool cTimeCounter::IsUsing() const
{
	return ((m_done == false) && (m_duration > 0.0f));
}

inline void cTimeCounter::Reset()
{
	m_timer = 0.0f;
	m_done = false;
}

inline void cTimeCounter::Clear()
{
	m_timer = 0.0f;
	m_done = false;
	m_duration = 0.0f;
}

inline void cTimeCounter::Continue()
{
	m_done = false;
	m_timer -= m_duration;
}

#endif // __TIME_COUNTER_H__